package tgc.edu.ljc.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tgc.edu.ljc.custom.CommonService;
import tgc.edu.ljc.entity.SysDept;
import tgc.edu.ljc.repository.SysDeptRepository;
@Service
public class SysDeptService extends CommonService<SysDept, Integer>{
	@Autowired
	private SysDeptRepository sysDeptDAO;

	public List<SysDept> findByParentIsNullOrderByIdx1() {
		return sysDeptDAO.findByParentIsNullOrderByIdx1();
	}

	public List<SysDept> findByParent_id(Integer id) {
		return sysDeptDAO.findByParent_id(id);
		
	}
	public List<SysDept> findByParentId(Integer id){
		return sysDeptDAO.findByParentId(id);
	}
	
	public void findChildrenId(Integer id,List<Integer> ids){
		ids.add(id);
		List<SysDept> list = findByParentId(id);
		for (SysDept dept : list) {
			findChildrenId(dept.getId(), ids);
		}
	}
	
	public List<Integer> findAllChildrenId(Integer id){
		List<Integer> ids= new ArrayList<>();
		findChildrenId(id, ids);
		return ids;
	}
}
